package com.arges.web.serviceImpl;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.arges.web.dao.GenericDao;
import com.arges.web.dao.NoticeDao;
import com.arges.web.domain.pojo.Notice;
import com.arges.web.page.PageInfo;
import com.arges.web.service.NoticeManager;

@Service
public class NoticeManagerImpl extends GenericManageImpl<Notice, Notice> implements NoticeManager
{

	@Autowired
	private NoticeDao noticeDao;

	@Override
	public PageInfo<Notice> getPageNotice(PageInfo<Notice> pageInfo, String title)
	{
		Criterion criterion = null;
		if (StringUtils.isNotBlank(title))
		{
			criterion = Restrictions.like("title", title, MatchMode.ANYWHERE);
		}

		PageInfo<Notice> page = noticeDao.findAll(pageInfo, Notice.class, criterion);

		return page;
	}

	@Override
	public Notice findNoticeById(long parseLong)
	{

		return noticeDao.get(parseLong);
	}

	@Override
	public void deleteByIds(String ids)
	{
		String[] split = ids.split(",");
		Long[] deleteId = new Long[split.length];
		for (int i = 0; i < split.length; i++)
		{
			deleteId[i] = Long.valueOf(split[i]);
		}
		noticeDao.deleteNoticeByIds(deleteId);
	}

	@Override
	public GenericDao<Notice, Long> getGenericDao()
	{
		return noticeDao;
	}

}
